﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sharp.Domain.PlatformBoundedContext.MasterDataModule.Aggregates;
using Sharp.Domain.Model;
using Sharp.Domain.Repositories;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Data;

namespace Sharp.Domain.PlatformBoundedContext.MasterDataModule.Services
{
    /// <summary>
    /// 主数据服务
    /// </summary>
    public partial class MasterDataService : IMasterDataService
    {
        #region 私有字段

        private readonly IRepositoryContext _repositoryContext;
        private readonly IMasterDataRepository _masterDataRepository;
        #endregion

        #region 构造函数

        /// <summary>
        ///     初始化一个新的实例。
        /// </summary>
        /// <param name="repositoryContext">仓储上下文。</param>
        /// <param name="repository">主数据仓储。</param> 
        public MasterDataService(IRepositoryContext repositoryContext,
            IMasterDataRepository repository)
        {
            _repositoryContext = repositoryContext;
            _masterDataRepository = repository;
        }

        #endregion

        /// <summary>
        /// 代码项翻译成文字项
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string Code2Text(string code)
        {
            var info = _masterDataRepository.Get(x => x.Code == code);
            return info.Name;
        }

        /// <summary>
        /// 删除主数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Result DeleteMasterData(Guid[] ids)
        {
            Result res = new Result();
            _masterDataRepository.Remove(ids);
            _repositoryContext.Commit();
            return res;
        }
    }
}
